<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1"/>
    <meta http-equiv="X-UA-Compatible" content="IE=9"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta charset="utf-8">
	<title>桥接模式</title>
	<script type="text/javascript" src="js/commonUtil.js"></script>
	<script type="text/javascript" src="js/jquery-3.0.0.min.js"></script>
</head>
<body>
	<input type="button" id="inp" value="我是数据..." />
<script type="text/javascript">
	
	// 桥接模式：将抽象部分与它的实现部分分离，使它们都可以独立地变化
	/*
	// 事件监听回调机制
	$(function(){
		var inp = $('#inp');
		Jerry.eventUtil.addHandler(inp, 'click', openRequest);

		function openRequest () {
			alert('向后台发送数据: ' + this.value);
		}
	})
	
	$(function(){
		var inp = $('#inp');
		Jerry.eventUtil.addHandler(inp, 'click', openFunction);

		// 利用桥接模式分开，便于单元测试
		function openFunction () {
			openRequest(this.value);
		}

		function openRequest (msg) {
			alert('向后台发送数据: ' + msg);
		}
		//openRequest('我也是数据...');
	})
	*/

	/*
	// 特权函数
	var PublicClass = function () {
		// private
		var name = 'z3';
		// 特权函数
		this.getName = function () {
			return name;
		}
	}

	var PublicClass = function () {
		var privateMethod = function () {
			alert('我是一个函数');
		};
		// 特权函数
		this.bridgeMethod = function () {
			return privateMethod();
		}
	}

	var p = new PublicClass();
	p.bridgeMethod();
	*/

	// 用桥把多个单元组合到一起
	// 使每个单元可以独立开发
	var Class1 = function (a, b, c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}

	var Class2 = function (d, e) {
		this.d = d;
		this.e = e;
	}

	var BridgeClass = function (a, b, c, d, e) {
		this.class1 = new Class1(a, b, c);
		this.class2 = new Class1(d, e);
	}

</script>
</body>
</html>